import {
	copy
} from '../libs/utils.js'
import store from '../store'
import animationFn from '../libs/animation.js'

let calcAnimation = myItem => {
	var anim = myItem.animation,
		obj = {
			aniBoxStyle: '',
			animationStyle: ''
		};
	if (anim && !store.state.$editMode) {
		anim = copy(anim);
		animationFn(anim);
		if(!anim.animation || anim.repeatCount === 0){
			return obj
		}
		obj.aniBoxStyle = 'transform:translate(' + anim.x + 'rpx,' + anim.y + 'rpx) scale(' + anim.scaleX + ',' + anim.scaleY +
			') rotate(' + anim.rotate + 'deg);opacity:'+anim.defaultOpacity+';'
		setTimeout(() => {
			obj.aniBoxStyle = 'transform:translate(0,0) scale(1,1) rotate(0deg);opacity:'+anim.opacity+';transition-delay:' + anim.delay +
				's;transition-duration:' + anim.duration + 's;transition-timing-function:' + anim.curve + ';';
			obj.animationStyle = 'animation-name:' + anim.animation + ';animation-duration:' + anim.duration +
				's;animation-delay:' +
				anim.delay + 's;animation-timing-function:' + anim.curve + ';animation-iteration-count:'+anim.repeatCount+';';
		})
	}
	return obj
}
export default {
	data() {
		return {
			animationInfo: {}
		}
	},
	methods: {
		calcAnimation(myItem) {
			this.animationInfo = calcAnimation(myItem)
		}
	}
}
